﻿using System;
using System.Text;

namespace Workdays
{
    class Workdays
    {
        static DateTime[] Holydays = 
        {
            new DateTime(1, 1, 1),
            new DateTime(1, 3, 3),
            new DateTime(1, 5, 1),
            new DateTime(1, 5, 6),
            new DateTime(1, 5, 24),
            new DateTime(1, 9, 6),
            new DateTime(1, 9, 22),
            new DateTime(1, 12, 24),
            new DateTime(1, 12, 25),
            new DateTime(1, 12, 26)
        };

        static bool IsHolyday(DateTime date)
        {
            for (int i = 0, length = Holydays.Length; i < length; i++)
            {
                if (date.DayOfYear == Holydays[i].DayOfYear)
                {
                    return true;
                }
            }
            return false;
        }

        static bool isWeekend(DateTime date)
        {
            if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
            {
                return true;
            }
            return false;
        }

        static void ParseDate(string input, out int year, out int month, out int day)
        {
            StringBuilder number = new StringBuilder();
            //[0] = Year, [1] = Month, [2] = Day
            int[] date = new int[3];
            int dateIndex = 0;
            //Search Year, mounth and day in the string
            for (int charIndex = 0, length = input.Length; charIndex < length; charIndex++)
			{
                if (char.IsDigit(input[charIndex]))
                {
                    number.Append(input[charIndex]);
                }
                else
                {
                    if (number.Length > 0)
                    {
                        date[dateIndex++] = int.Parse(number.ToString());
                        number.Clear();
                    }
                }
			}
            if (number.Length > 0)
            {
                date[dateIndex] = int.Parse(number.ToString());
            }
            year = date[0];
            month = date[1];
            day = date[2];
        }
        static int WorkDays(DateTime endDate)
        {
            DateTime date = DateTime.Now;
            int workDays = 0;
            if (endDate > date)
            {
                for (DateTime currentDate = endDate; currentDate >= date; currentDate = currentDate.AddDays(-1))
                {
                    if (isWeekend(currentDate) || IsHolyday(currentDate))
                    {
                        continue;
                    }
                    workDays++;
                }
            }
            else
            {
                for (DateTime currentDate = endDate; currentDate < date; currentDate = currentDate.AddDays(1))
                {
                    if (isWeekend(currentDate) || IsHolyday(currentDate))
                    {
                        continue;
                    }
                    workDays++;
                }
            }
            return workDays;
        }
        static void Main()
        {
            int year, month, day, workDays;
            string inputString;

            Console.Write("Enter the date [ Year - Mounth - Day ]: ");
            inputString = Console.ReadLine();

            ParseDate(inputString, out year, out month, out day);
            workDays = WorkDays(new DateTime(year, month, day));
            Console.WriteLine("{0} work days.", workDays);
        }
    }
}